use Component;
use Operation;
use Operations;

package OperationManager;
@ISA = qw/Component/;

sub new{
    my $class = shift;
    my $self = {};

    bless $self, $class;
    $self->init(@_);

    return $self;
} # new

sub init{
    my $self = shift;

    $self->dependencies(qw/DependencyResolver LogManager/);
} # init


# Runs the given operations with the specified shared set of parameters
# The reference to the parameter hash is passed as a first argument
# The rest of the argument list are names to the operations to be performed
# The first failure or the last succesful result is returned
sub runOperations{
    my $self = shift;
    my $params = shift;
   
    my $lm = $self->{LogManager};

    my $result;
    foreach my $opName(@_){
	$lm->log(ref($self)."- Instancing Operation: ".$opName);
	my $op = eval ($opName."->new");
	$op->params($params);
	$self->{DependencyResolver}->resolveDependencies($op);

	$result = $op->perform;

	return $result unless($result->is("SUCCESS"));
    }
    return $result;
}

1;

